add a test of utf8 filename handlig.
authortsteven4 <tsteven4@gmail.com>
Tue, 28 Nov 2017 22:27:58 +0000 (15:27 -0700)
committertsteven4 <tsteven4@gmail.com>
Tue, 28 Nov 2017 22:27:58 +0000 (15:27 -0700)
build_and_test
test_encoding_utf8 [new file with mode: 0755]

index 2c37da12b858b2fe4009705f64cc135117426308..d0ace4d0041adaa87d002a2b67332ac2744fd0c5 100755 (executable)
@@ -33,6 +33,7 @@ make gpsbabel.html
 make check
 # test for mangled encoding of command line arguments
 ./test_encoding
+./test_encoding_utf8
 #make torture
 rm -f vg.log
 ./vtesto -l -j vg.log
diff --git a/test_encoding_utf8 b/test_encoding_utf8
new file mode 100755 (executable)
index 0000000..8abe07a
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/bash
+# this file should be encoded in utf8
+
+BASEPATH=`dirname $0`
+PNAME=${PNAME:-${BASEPATH}/gpsbabel}
+REFERENCE=${BASEPATH}/reference
+
+TMPDIR=${GBTEMP:-/tmp}/gpsbabel.$$
+mkdir -p $TMPDIR
+trap "rm -fr $TMPDIR" 0 1 2 3 15
+
+errorcount=0
+
+cmap=$(locale charmap)
+if [ "${cmap}" == "UTF-8" ] ; then
+
+echo "Running utf-8 file name encoding test"
+filenamebase=test_encoding_fileαβγ
+
+# test input file name mangling with gpsbabel::File
+  echo "testing input file name with gpsbabel::File"
+  rm -f ${TMPDIR}/test_encoding_file*
+  cp ${REFERENCE}/bounds-test.gpx ${TMPDIR}/${filenamebase}.gpx
+  ${PNAME} -i gpx -f ${TMPDIR}/${filenamebase}.gpx -o kml -F ${TMPDIR}/test_encoding_fileo.kml || {
+    echo "ERROR: The input file name was mangled."
+    errorcount=`expr $errorcount + 1`
+  }
+
+# test output file name mangling with gpsbabel::File
+  echo "testing output file name with gpsbabel::File"
+  rm -f ${TMPDIR}/test_encoding_file*
+  ${PNAME} -i gpx -f ${REFERENCE}/bounds-test.gpx -o kml -F ${TMPDIR}/${filenamebase}.kml
+  count=$(ls -1 -l ${TMPDIR}/${filenamebase}.kml 2>/dev/null | wc -l)
+  if [ $count -lt 1 ]; then
+    echo "ERROR: The output file name was mangled."
+    errorcount=`expr $errorcount + 1`
+  fi
+
+# test input file name mangling with gbfile stdapi
+  echo "testing input file name with gbfile stdapi"
+  rm -f ${TMPDIR}/test_encoding_file*
+  cp ${REFERENCE}/unicsv_subsec.csv ${TMPDIR}/${filenamebase}.csv
+  ${PNAME} -i unicsv -f ${TMPDIR}/${filenamebase}.csv -o kml -F ${TMPDIR}/test_encoding_fileo.kml || {
+    echo "ERROR: The input file name was mangled."
+    errorcount=`expr $errorcount + 1`
+  }
+
+# test output file name mangling with gbfile stdapi
+  echo "testing output file name with gbfile stdapi"
+  rm -f ${TMPDIR}/test_encoding_file*
+  ${PNAME} -i gpx -f ${REFERENCE}/bounds-test.gpx -o unicsv -F ${TMPDIR}/${filenamebase}.csv
+  count=$(ls -1 -l ${TMPDIR}/${filenamebase}.csv 2>/dev/null | wc -l)
+  if [ $count -lt 1 ]; then
+    echo "ERROR: The output file name was mangled."
+    errorcount=`expr $errorcount + 1`
+  fi
+
+# test input file name mangling with gbfile gzapi
+  echo "testing input file name with gbfile gzapi"
+  rm -f ${TMPDIR}/test_encoding_file*
+  cp ${REFERENCE}/sample.gtm.gz ${TMPDIR}/${filenamebase}.gtm.gz
+  ${PNAME} -i gtm -f ${TMPDIR}/${filenamebase}.gtm.gz -o kml -F ${TMPDIR}/test_encoding_fileo.kml || {
+    echo "ERROR: The input file name was mangled."
+    errorcount=`expr $errorcount + 1`
+  }
+
+# test output file name mangling with gbfile gzapi
+  echo "testing output file name with gbfile gzapi"
+  rm -f ${TMPDIR}/test_encoding_file*
+  ${PNAME} -i gpx -f ${REFERENCE}/bounds-test.gpx -o gtm -F ${TMPDIR}/${filenamebase}.gtm.gz
+  count=$(ls -1 -l ${TMPDIR}/${filenamebase}.gtm.gz 2>/dev/null | wc -l)
+  if [ $count -lt 1 ]; then
+    echo "ERROR: The output file name was mangled."
+    errorcount=`expr $errorcount + 1`
+  fi
+
+# TODO: add tests to cover formats that use other open methods.
+#       for example shape files.
+
+else
+  echo "$0 cannot run without the UTF-8 charmap."
+fi
+
+exit $errorcount